/*
 * Copyright (c) 1990, 2022, shwfed and/or its affiliates. All rights reserved.
 *
 * @date: 2022-08-24
 *
 */
package cn.junglead.common.utils;

import javax.crypto.KeyGenerator;
import java.security.NoSuchAlgorithmException;

/**
 * 用于常见的AES和DES密码学工具的基类
 *
 * @author Gary.Wang
 * @version 1.0
 */
public abstract class CipherBase {

    /**
     * 输出格式为 BASE64
     */
    public static int FORMAT_BASE64 = 1;

    /**
     * 输出格式为 HEX
     */
    public static int FORMAT_HEX = 2;

    /**
     * 生成加密密钥
     * @param algorithms 算法
     * @param keyLength 密钥长度，默认为128
     * @return 返回Key对象
     *
     * @throws NoSuchAlgorithmException 不存在的算法异常
     */
    protected static KeyGenerator generateKeygen(String algorithms, int keyLength) throws NoSuchAlgorithmException {
        KeyGenerator keygen = KeyGenerator.getInstance(algorithms);
        keygen.init(keyLength);
        return keygen;
    }
}
